package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.SpecParamMapper;
import com.leyou.item.service.SpecParamService;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SpecParamImpl extends ServiceImpl<SpecParamMapper, SpecParam> implements SpecParamService {
    @Override
    public List<SpecParamDTO> queryParams(Long categoryId, Long groupId, Boolean searching) {
        Boolean isCategoryOn = categoryId != null;
        Boolean isGroupOn = groupId != null;
        Boolean isSearchingOn = searching != null;

        //有分类，根据分类查询，有分组根据分组查询，有searching条件要根据searching条件,动态sql


        return SpecParamDTO.convertEntityList(query()
                .eq(isCategoryOn, "category_id", categoryId)
                .eq(isGroupOn, "group_id", groupId)
                .eq(isSearchingOn, "searching", searching)
                .list());
    }
}
